package 异常的学习;


//给定一个数列，数列中元素的个数是奇数。
//
//        已知数列中有一个数字仅出现了一次，而其他数字都恰好出现了两次。
//
//        请你编写程序找到仅出现了一次的那个数字。
//import java.util.Scanner;
//public class PTA_other {
//    public  static Scanner sc = new Scanner(System.in);
//    public static void main(String[] args) {
//        int n = sc.nextInt();
//        int[] arr = new int[n];
//        for (int i = 0; i < n; i++) {
//            arr[i] = sc.nextInt();
//        }
//        int ans = 0;
//        for (int i = 0; i < n; i++) {
//            ans ^= arr[i];
//        }
//        System.out.println(ans);
//    }
//}

import java.util.Scanner;

// 复数类，处理复数的基本运算
class Complex {
    private double realPart;   // 实部
    private double imaginaryPart; // 虚部
    public Complex() {
        this.realPart = 0.0;
        this.imaginaryPart = 0.0;
    }
    public Complex(double realPart, double imaginaryPart) {
        this.realPart = realPart;
        this.imaginaryPart = imaginaryPart;
    }
    public void setRealPart(double realPart) {
        this.realPart = realPart;
    }
    public void setImaginaryPart(double imaginaryPart) {
        this.imaginaryPart = imaginaryPart;
    }
    public Complex add(Complex other) {
        double real = this.realPart + other.realPart;
        double imaginary = this.imaginaryPart + other.imaginaryPart;
        return new Complex(real, imaginary);
    }
    public Complex sub(Complex other) {
        double real = this.realPart - other.realPart;
        double imaginary = this.imaginaryPart - other.imaginaryPart;
        return new Complex(real, imaginary);
    }
    @Override
    public String toString() {
        // 处理特殊情况：实部为0或虚部为0
        if (imaginaryPart == 0)
            return String.format("%.1f", realPart);
        if (realPart == 0)
            return String.format("%.1fi", imaginaryPart);
        if (imaginaryPart > 0)
            return String.format("%.1f+%.1fi", realPart, imaginaryPart);
        else
            return String.format("%.1f%.1fi", realPart, imaginaryPart);
    }
}

// 测试类
public class PTA_other {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Complex a = new Complex();
        Complex b = new Complex();
        a.setRealPart(in.nextDouble());
        a.setImaginaryPart(in.nextDouble());
        b.setRealPart(in.nextDouble());
        b.setImaginaryPart(in.nextDouble());
        System.out.println(a);
        System.out.println(b);
        System.out.println(a.add(b));
        System.out.println(a.sub(b));
        in.close();
    }
}